package com.module.shici.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.fenghuajueli.libbasecoreui.baseswitch.PublicFunction;
import com.fenghuajueli.libbasecoreui.mvp.BaseActivity;
import com.fenghuajueli.module_route.CommonRoute;
import com.fenghuajueli.module_route.ShiciRoute;
import com.module.shici.bean.YinpinData;
import com.module.shici.databinding.ModuleShiciActivityShiciBinding;
import com.module.shici.adapter.FunctionAdapter;
import com.module.shici.room.Music;
import com.sw.chinesewriteboard.activity.EnglishActivity;
import com.sw.chinesewriteboard.activity.ListActivity;
import com.sw.chinesewriteboard.activity.LocalActivity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
@Route(path = ShiciRoute.SHICI_MAIN)
public class ShiciActivity extends BaseActivity {
    private String[] funcs = {"打卡记录","古诗词","文言文","现代诗","作者",
            "唐诗","宋词","楚辞","诗经","乐府","古文观止","我的字帖","拼音贴","英语贴","故事","哄睡","晨起","喜欢"};
    private ModuleShiciActivityShiciBinding binding;
    private FunctionAdapter adapter;
    private YinpinData yinpinData = new YinpinData();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ModuleShiciActivityShiciBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initData();
        initAdapter();
    }

    private void initData() {

    }


    private void initAdapter() {
        List<String> list = new ArrayList<>();
        for (int i = 0;i < funcs.length;i++){
            list.add(funcs[i]);
        }
        adapter = new FunctionAdapter(this,list);
        binding.functionList.setLayoutManager(new LinearLayoutManager(this, RecyclerView.VERTICAL,false));
        binding.functionList.setAdapter(adapter);

        adapter.setOnItemClickListener(new FunctionAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                doAction(position);
            }
        });
    }

    private void doAction(int position) {
        String title = funcs[position];
        if (position == 0){
            ARouter.getInstance().build(ShiciRoute.SHICI_CHECKIN).navigation();
        }else if (position == 1){
            startShiCiActivity(title,1);
        }else if (position == 2){
            startShiCiActivity(title,1);
        }else if (position == 3){
            startShiCiActivity(title,1);
        }else if (position == 4){
            startActivity(new Intent(this, AuthorActivity.class));
        }else if (position == 11){
            jumpToMakeZitie(title);
        }else if (position == 12){
            jumpToMakeZitie(title);
        }else if (position == 13){
            jumpToMakeZitie(title);
        } else if (position == 14){
            startYinPinListActivity(title, yinpinData.getStoryList(), 2);
        } else if (position == 15){
            startYinPinListActivity(title, yinpinData.getPianoList(), 4);
        } else if (position == 16){
            startYinPinListActivity(title, yinpinData.getErgeList(), 3);
        } else if (position == 17){
            startYinPinListActivity(title, yinpinData.getCollectList(), 1);
        }else {
            startShiCiActivity(title,3);
        }
    }




    private void startShiCiActivity(String title,int type){
        Intent intent = new Intent(this, MyShiCiActivity.class);
        intent.putExtra("title",title);
        intent.putExtra("type",type);
        startActivity(intent);
    }

    private void startYinPinListActivity(String title, List<Music> musicList, int imgType) {
        Intent intent = new Intent(this, YinPinListActivity.class);
        intent.putExtra("title", title);
        intent.putExtra("musicList", (Serializable) musicList);
        intent.putExtra("imgType", imgType);
        startActivity(intent);
    }

    private void jumpToMakeZitie(String zitieType) {
        if (!PublicFunction.checkCanUsedByPosition(3, true)) {
            return;
        }
        if ("英语贴".equals(zitieType)) {
            Intent intent = new Intent(this, EnglishActivity.class);
            startActivity(intent);
        } else if ("拼音贴".equals(zitieType)) {
            Intent intent = new Intent(this, LocalActivity.class);
            startActivity(intent);
        } else if ("我的字帖".equals(zitieType)) {
            Intent intent = new Intent(this, ListActivity.class);
            startActivity(intent);
        }
    }
}
